home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / inc / irit_sm.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  6.1 KB  |  203 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, Jan. 1992   *
  5. ******************************************************************************
  6. * Main definition Header file  for Irit - the 3d polygonal solid modeller.   *
  7. *****************************************************************************/
  8.  
  9. #ifndef    IRIT_SM_H
  10. #define    IRIT_SM_H
  11.  
  12. /* Note program version should also be updated in *.c modules, in few        */
  13. /* places, as some system can not chain strings in the pre-processor level.  */
  14. #define  VERSION    "Version 4.0"             /* Program version. */
  15. #define  COPYRIGHT    "(C) Copyright 1989/90/91/92/93 Gershon Elber"
  16.  
  17. #include <string.h>
  18.  
  19. #ifndef    NULL
  20. #define    NULL    0
  21. #endif /* NULL */
  22.  
  23. #ifndef    TRUE
  24. #define    TRUE    1
  25. #define    FALSE    0
  26. #endif /* TRUE */
  27.  
  28. #ifdef VoidPtr
  29. #undef VoidPtr
  30. #endif /* VoidPtr */
  31.  
  32. #ifdef NO_VOID_PTR
  33. #define VoidPtr        char *
  34. #else
  35. #define VoidPtr        void *
  36. #endif /* NO_VOID_PTR */
  37.  
  38. #if !defined(FLOAT) && !defined(DOUBLE)
  39. #ifdef __MSDOS__
  40. #define FLOAT
  41. typedef    float        RealType;        /* On IBMPC to reserve memory... */
  42. #else
  43. #define DOUBLE
  44. typedef    double        RealType;
  45. #endif /* __MSDOS__ */
  46. #endif /* !FLOAT && !DOUBLE */
  47.  
  48. typedef    unsigned char    ByteType;
  49.  
  50. typedef    RealType    PointType[3];    /* For X, Y, Z coordinates of point. */
  51. typedef RealType    VectorType[3]; /* For X, Y, Z coordinates of vector. */
  52. typedef RealType    LineType[3];          /* A, B, C in Ax + By + C = 0. */
  53. typedef RealType    NormalType[3];        /* Unit normalized normal coeff. */
  54. typedef RealType    PlaneType[4];            /* Plane equation coeff. */
  55. typedef RealType    MatrixType[4][4];       /* Homogeneous transform. */
  56. typedef PointType    BBoxType[2];          /* Axis parallel bounding box. */
  57.  
  58. #define EPSILON        1e-5
  59. #define INFINITY    1e6
  60.  
  61. #ifndef M_PI
  62. #define M_PI    3.14159265358979323846
  63. #endif /* M_PI */
  64.  
  65. #define LINE_LEN_LONG    256           /* Lines read from stdin/files... */
  66. #define LINE_LEN    81           /* Lines read from stdin/files... */
  67. #define LINE_LEN_SHORT    31           /* Lines read from stdin/files... */
  68. #define OBJ_NAME_LEN    31                /* Names of objects. */
  69. #define FILE_NAME_LEN    13           /* Name (8) + Type (3) + Dot (1). */
  70. #define PATH_NAME_LEN    80                      /* Name with full Path */
  71.  
  72. /* Follows by general purpose helpfull macros: */
  73. #ifndef MIN
  74. #define MIN(x, y)        ((x) > (y) ? (y) : (x))
  75. #endif /* MIN */
  76. #ifndef MAX
  77. #define MAX(x, y)        ((x) > (y) ? (x) : (y))
  78. #endif /* MAX */
  79. #define BOUND(x, Min, Max)    (MAX(MIN(x, Max), Min))
  80.  
  81. #define ABS(x)            ((x) > 0 ? (x) : (-(x)))
  82. #define SQR(x)            ((x) * (x))
  83. #define SIGN(x)            ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
  84.  
  85. #define SWAP(type, x, y)    { type temp = (x); (x) = (y); (y) = temp; }
  86.  
  87. #define REAL_TO_INT(R)        ((int) (R + 0.5))
  88. #define REAL_PTR_TO_INT(R)    ((int) ((*R) + 0.5))
  89.  
  90. #define APX_EQ(x, y)        (ABS(x - y) < EPSILON)
  91. #define PT_APX_EQ(Pt1, Pt2)    (APX_EQ(Pt1[0], Pt2[0]) && \
  92.                  APX_EQ(Pt1[1], Pt2[1]) && \
  93.                  APX_EQ(Pt1[2], Pt2[2]))
  94. #define PLANE_APX_EQ(Pl1, Pl2)    (APX_EQ(Pl1[0], Pl2[0]) && \
  95.                  APX_EQ(Pl1[1], Pl2[1]) && \
  96.                  APX_EQ(Pl1[2], Pl2[2]) && \
  97.                  APX_EQ(Pl1[3], Pl2[3]))
  98.  
  99.  
  100. #define PT_CLEAR(Pt)        { Pt[0] = Pt[1] = Pt[2] = 0.0; }
  101.  
  102. #define PT_SCALE(Pt, Scalar)    { Pt[0] *= Scalar; \
  103.                   Pt[1] *= Scalar; \
  104.                   Pt[2] *= Scalar; \
  105.                     }
  106.  
  107. /* The memcpy is sometimes defined to get (char *) pointers and sometimes    */
  108. /* (void *) pointers. To be compatible with both it is coerced to (char *).  */
  109. #define PT_COPY(PtDest, PtSrc)      memcpy((char *) (PtDest), (char *) (PtSrc), \
  110.                             3 * sizeof(RealType))
  111. #define PLANE_COPY(PlDest, PlSrc) memcpy((char *) (PlDest), (char *) (PlSrc), \
  112.                             4 * sizeof(RealType))
  113. #define MAT_COPY(Dest, Src)      memcpy((char *) (Dest), (char *) (Src), \
  114.                             16 * sizeof(RealType))
  115. #define GEN_COPY(Dest, Src, Size) memcpy((char *) (Dest), (char *) (Src), Size)
  116. #define ZAP_MEM(Dest, Size)      memset((char *) (Dest), 0, Size);
  117.  
  118. #define PT_LENGTH(Pt)        sqrt(SQR(Pt[0]) + SQR(Pt[1]) + SQR(Pt[2]))
  119.  
  120. #define PT_NORMALIZE(Pt)    { RealType Size = PT_LENGTH(Pt); \
  121.                   Pt[0] /= Size; \
  122.                   Pt[1] /= Size; \
  123.                   Pt[2] /= Size; \
  124.                 }
  125.  
  126. #define PT_BLEND(Res, Pt1, Pt2, t) \
  127.                 { Res[0] = Pt1[0] * t + Pt2[0] * (1 - t); \
  128.                   Res[1] = Pt1[1] * t + Pt2[1] * (1 - t); \
  129.                   Res[2] = Pt1[2] * t + Pt2[2] * (1 - t); \
  130.                     }
  131.  
  132. #define PT_ADD(Res, Pt1, Pt2)    { Res[0] = Pt1[0] + Pt2[0]; \
  133.                   Res[1] = Pt1[1] + Pt2[1]; \
  134.                   Res[2] = Pt1[2] + Pt2[2]; \
  135.                     }
  136.  
  137. #define PT_SUB(Res, Pt1, Pt2)    { Res[0] = Pt1[0] - Pt2[0]; \
  138.                   Res[1] = Pt1[1] - Pt2[1]; \
  139.                   Res[2] = Pt1[2] - Pt2[2]; \
  140.                 }
  141.  
  142. #define PT_SWAP(Pt1, Pt2)    { SWAP(RealType, Pt1[0], Pt2[0]); \
  143.                   SWAP(RealType, Pt1[1], Pt2[1]); \
  144.                   SWAP(RealType, Pt1[2], Pt2[2]); \
  145.                 }
  146.  
  147. #define DOT_PROD(Pt1, Pt2)    (Pt1[0] * Pt2[0] + \
  148.                  Pt1[1] * Pt2[1] + \
  149.                  Pt1[2] * Pt2[2])
  150.  
  151. #define CROSS_PROD(PtRes, Pt1, Pt2) \
  152.                 { PtRes[0] = Pt1[1] * Pt2[2] - Pt1[2] * Pt2[1]; \
  153.                   PtRes[1] = Pt1[2] * Pt2[0] - Pt1[0] * Pt2[2]; \
  154.                   PtRes[2] = Pt1[0] * Pt2[1] - Pt1[1] * Pt2[0]; }
  155.  
  156. #define DEG2RAD(Deg)        ((Deg) * M_PI / 180.0)
  157. #define RAD2DEG(Rad)        ((Rad) * 180.0 / M_PI)
  158.  
  159. #if defined(_AIX) || defined(sgi) || defined(DJGCC) || defined(OS2GCC) || defined(__WINNT__) || defined(AMIGA)
  160. #include <stdlib.h>
  161. #ifdef sgi
  162. #include <unistd.h>
  163. #endif /* sgi */
  164. #else
  165. VoidPtr malloc(unsigned int Size);
  166. void free(VoidPtr p);
  167. char *getenv(char *Name);
  168. int atoi(char *str);
  169. #endif /* _AIX || sgi || DJGCC || OS2GCC || __WINNT__ || AMIGA */
  170.  
  171. char *IritStrdup(char *s);
  172. void IritSleep(int MiliSeconds);
  173. void IritRandomInit(long Seed);
  174. RealType IritRandom(RealType Min, RealType Max);
  175. RealType IritCPUTime(int Reset);
  176. char *IritRealTimeDate(void);
  177.  
  178. #ifndef AMIGA
  179. void movmem(VoidPtr Src, VoidPtr Dest, int Len);
  180. #endif /* AMIGA */
  181. char *searchpath(char *Name);
  182.  
  183. #ifdef STRICMP
  184. int strnicmp(char *s1, char *s2, int n);
  185. int stricmp(char *s1, char *s2);
  186. #endif /* STRICMP */
  187.  
  188. #ifdef STRSTR
  189. char *strstr(char *s, char *Pattern);
  190. #endif /* STRSTR */
  191.  
  192. #ifdef STRDUP
  193. char *strdup(char *s);
  194. #endif /* STRDUP */
  195.  
  196. #ifdef GETCWD
  197. char *getcwd(char *s, int Len);
  198. #endif /* GETCWD */
  199.  
  200. void IritFatalError(char *Msg);
  201.  
  202. #endif    /* IRIT_SM_H */
  203.